package edu.bbu.BS.swing;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import edu.bbu.bs.backend.service.beans.RemoteBeanInterface;

public class RemoteClient {

	public static void main(String[] args) {
		try {
			// Context jndiContext = getInitialContext();
			Context jndiContext = new InitialContext();
			// Object ref = jndiContext.lookup("java:global/BS-Server-0.0.1-SNAPSHOT/BS-backend-0.0.1-SNAPSHOT/RemoteBean");
			// Object ref = jndiContext.lookup("RemoteBean");
			Object ref = jndiContext.lookup("java:global/BS-Server/BS-backend-0.0.1-SNAPSHOT/RemoteBean!edu.bbu.bs.interfaces.RemoteBeanInterface");

			// RemoteBeanInterface remoteBean = (RemoteBeanInterface) PortableRemoteObject.narrow(ref, RemoteBean.class);
			RemoteBeanInterface remoteBean = (RemoteBeanInterface) ref;

			System.out.println(remoteBean.osszead(10, 20));
		} catch (javax.naming.NamingException e) {
			e.printStackTrace();
		}
	}

	public static Context getInitialContext() throws javax.naming.NamingException {
		// Properties props = new Properties();
		// props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
		// props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
		// props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

		Properties props = new Properties();
		props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
		props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
		props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

		// optional. Defaults to localhost. Only needed if web server is running
		// on a different host than the appserver
		props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

		// optional. Defaults to 3700. Only needed if target orb port is not 3700.
		props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

		return new InitialContext(props);
	}

}
